package openadmin.model.control;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import openadmin.dao.Base;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

/**
 * <desc>class that stores information of attributes to be displayed in the view part of a class. </desc>
 * <responsibility>Represents all the views for users</responsibility>
 * <coperation>Interface Base - Class ViewRole - Class ActionClass</coperation>
 * @version  0.1
 * Created 06-05-2009
 * Modifier 18-09-2009 
 * Author Eduard
 * Modified Alfred 18-09-2009
*/
@Entity
@Table(name = "view", schema = "control", uniqueConstraints = @UniqueConstraint(columnNames = "description") )
public class View implements Base, java.io.Serializable {

	/** attribute that contains the identifier*/
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)	
	private Integer id;
	
	/** attribute that contains the description, unique value*/
	@Length(max = 40)
	@NotNull
	private String description;
	
	/** attribute that contains the relationship with actionClass*/
	@ManyToOne
	@JoinColumn(name = "actionclass", nullable= false)
	private ActionClass actionClass;
	
	/** Transient attribute that means that the system should make a log on any JPA operation of this class*/
	@Transient
	private boolean debuglog = true;
	
	/** Transient attribute that means that the system should make a historic on any JPA operation of this class*/
	@Transient
	boolean historiclog = false;	
		
	/** attribute that contains the relationship between role and view*/
	//@OneToMany(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER, mappedBy = "view")
	//private Set<ViewRole> viewRole = new HashSet<ViewRole>(0);


	/**
	 * Constructor of the class Action.
	 * without parameters
	 */
	public View() {
	}

	/**
	 * Constructor of the class Action.
	 * @param pDescription, is the description, (unique value), of the Action
	 */
	public View(String pDescription) {
		this.description = pDescription;
	}

	/**
	 * Constructor of the class Action.
	 * @param pActionclass, is the object ActionClass
	 * @param pDescription, is the description, (unique value), of the Action
	 */
	public View(ActionClass pActionclass, String pDescription) {
		
		this.actionClass = pActionclass;
		this.description = pDescription;
		
	}
	
	/** Getters and setters*/
	
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer pId) {
		this.id = pId;
	}

	public ActionClass getActionClass() {
		return this.actionClass;
	}

	public void setActionClass(ActionClass pActionClass) {
		this.actionClass = pActionClass;
	}
	
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String pDescription) {
		this.description = pDescription;
	}
	
	public boolean getDebugLog() {
		
		return debuglog;
	}
	
	public void setDebugLog(boolean pDebuglog) {
		
		debuglog = pDebuglog;
	
	}
	
	public boolean getHistoricLog() {
		return historiclog;
	}

	public void setHistoricLog(boolean historiclog) {
		this.historiclog = historiclog;
	}
	
	@Override
	public String toString(){
	      
		return description;
	
	}

}
